package com.nandi.emergencyinspection;

import android.app.ActivityManager;
import android.content.Context;

import androidx.camera.core.internal.utils.ImageUtil;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.module.AppGlideModule;
import com.nandi.emergencyinspection.utils.SSLSocketClient;

import java.io.InputStream;

import okhttp3.OkHttpClient;

/**
 * @创建者: qingsong
 * @创建时间: 2021/3/31 19:51
 * @描述:
 */
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//        if (activityManager != null) {
//            builder.setDefaultRequestOptions(ImageUtil.getOption());
//        }
    }


    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        //设置请求方式为okhttp 并设置okhttpClient的证书及超时时间
        OkHttpClient mHttpClient = new  OkHttpClient().newBuilder()
                .sslSocketFactory(SSLSocketClient.getSSLSocketFactory())
                .hostnameVerifier(SSLSocketClient.getHostnameVerifier())
                .build();
        OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(mHttpClient);
        registry.replace(GlideUrl.class, InputStream.class, factory);
    }
}